﻿<cfcomponent>
		
	<cfset api="f32f954a2cb3fa12b8268f46221d2dd8">
	<cfset ske="20563b986d23d3b8471950d1bd772882">
	<cfset ssk="1189d4a3f3174b21-170485">
	<cfset ver="1.0">
	<cfset std="221270">	
	
	<!--- Function to execute a query --->	
	<cffunction name="runQuery" access="public" returntype="xml">		
		<cfargument name="querystring" required="true" type="string">
		
		<cfset met="Printfection.PFQL.query">
		<cfset que=querystring>				
		<cfset asi="api_key=#api#method=#met#query=#que#session_key=#ssk#version=#ver##ske#">		
		<cfset sig=hash(asi,"MD5") >
		
		<cfhttp url="http://api.printfection.com/restserver.php?api_key=#api#&method=#met#&query=#que#&session_key=#ssk#&version=#ver#&api_sig=#LCase(sig)#" method="get" result="queryResponse">
		
		<cfset xmlResponse=xmlParse(queryResponse.Filecontent)>
		
		<cfreturn xmlResponse>
	</cffunction>
	
	<!--- Function to get product price --->	
	<cffunction name="getproductPrice" access="public" returntype="xml">		
		<cfargument name="productid" required="true" type="string">
		<cfargument name="rootcolorid" required="true" type="string">
		<cfargument name="rootsizeid" required="true" type="string">
		
		
		<cfset pid=productid>
		<cfset rcd=rootcolorid>
		<cfset rsd=rootsizeid>
		<cfset qty="1">
		<cfset met="Printfection.Products.getPrice">		
		<cfset asi="api_key=#api#method=#met#productid=#pid#qty=#qty#rootcolorid=#rcd#rootsizeid=#rsd#session_key=#ssk#version=#ver##ske#">		
		<cfset sig=hash(asi,"MD5") >
				
		<cfhttp url="http://api.printfection.com/restserver.php?api_key=#api#&method=#met#&productid=#pid#&qty=#qty#&rootcolorid=#rcd#&rootsizeid=#rsd#&session_key=#ssk#&version=#ver#&api_sig=#LCase(sig)#" method="get" result="queryResponse">
				
		<cfset xmlResponse=xmlParse(queryResponse.Filecontent)>
		
		<cfreturn xmlResponse>
	</cffunction>	
	
	<!--- Function to create cart --->
	<cffunction name="createCart" access="public" returntype="xml">
		
		<cfset met="Printfection.Carts.create">		
		<cfset asi="api_key=#api#method=#met#session_key=#ssk#version=#ver##ske#">
		<cfset sig=hash(asi,"MD5") >
		
		<cfhttp url="http://api.printfection.com/restserver.php?api_key=#api#&method=#met#&session_key=#ssk#&version=#ver#&api_sig=#LCase(sig)#" method="get" result="createcartResponse">
		
		<cfset xmlResponse=xmlParse(createcartResponse.Filecontent)>
		
		<cfreturn xmlResponse>
	</cffunction>
	
	<!--- Function to add product to the cart --->
	<cffunction name="addproducttoCart" access="public" returntype="xml">
		<cfargument name="cartkey" required="true" type="string">
		<cfargument name="productid" required="true" type="string">
		<cfargument name="rootcolorid" required="true" type="string">
		<cfargument name="quantity" required="true" type="string">
		<cfargument name="rootsizeid" required="true" type="string">
		
		<cfset cak=cartkey>
		<cfset pid=productid>
		<cfset rcd=rootcolorid>
		<cfset qty=quantity>
		<cfset rsd=rootsizeid>
		<cfset met="Printfection.Carts.addProduct">		
		<cfset asi="api_key=#api#cart_key=#cak#method=#met#productid=#pid#qty=#qty#rootcolorid=#rcd#rootsizeid=#rsd#session_key=#ssk#version=#ver##ske#">
		<cfset sig=hash(asi,"MD5") >
		
		<cfhttp url="http://api.printfection.com/restserver.php?api_key=#api#&cart_key=#cak#&method=#met#&productid=#pid#&qty=#qty#&rootcolorid=#rcd#&rootsizeid=#rsd#&session_key=#ssk#&version=#ver#&api_sig=#LCase(sig)#" method="get" result="addprotocartResponse">
		
		<cfset xmlResponse=xmlParse(addprotocartResponse.Filecontent)>
		
		<cfreturn xmlResponse>
	</cffunction>
	
	<!--- Function to remove product from cart --->
	<cffunction name="removeproductfromCart" access="public" returntype="xml">
		<cfargument name="cartkey" required="true" type="string">
		<cfargument name="productid" required="true" type="string">
		<cfargument name="rootcolorid" required="true" type="string">
		<cfargument name="rootsizeid" required="true" type="string">
		
		<cfset cak=cartkey>
		<cfset pid=productid>
		<cfset rcd=rootcolorid>
		<cfset rsd=rootsizeid>
		<cfset met="Printfection.Carts.removeProduct">		
		<cfset asi="api_key=#api#cart_key=#cak#method=#met#productid=#pid#rootcolorid=#rcd#rootsizeid=#rsd#session_key=#ssk#version=#ver##ske#">
		<cfset sig=hash(asi,"MD5") >
		
		<cfhttp url="http://api.printfection.com/restserver.php?api_key=#api#&cart_key=#cak#&method=#met#&productid=#pid#&rootcolorid=#rcd#&rootsizeid=#rsd#&session_key=#ssk#&version=#ver#&api_sig=#LCase(sig)#" method="get" result="removeprofromCartResponse">
		
		<cfset xmlResponse=xmlParse(removeprofromCartResponse.Filecontent)>
		
		<cfreturn xmlResponse>
	</cffunction>
	
	<!--- Function to redirect the user to checkout process --->
	<cffunction name="checkout" access="public" returntype="void">
		<cfargument name="cartkey" required="true" type="string">
		
		<cfset cak=cartkey>		
		<cfset asi="api_key=#api#cart_key=#cak#session_key=#ssk#storeid=#std#version=#ver##ske#">
		<cfset sig=hash(asi,"MD5") >
		
		<cfoutput><cflocation url="http://www.printfection.com/app/checkout.php?api_key=#api#&cart_key=#cak#&session_key=#ssk#&storeid=#std#&version=#ver#&api_sig=#LCase(sig)#"></cfoutput>
	</cffunction>

</cfcomponent>